{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31db9bca",
   "metadata": {},
   "source": [
    "## 模板介绍"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2beb5e66",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2f882de",
   "metadata": {},
   "source": [
    "**思考 : 网站如何向客户端返回一个漂亮的页面呢？**\n",
    "\n",
    "提示 :\n",
    "- 漂亮的页面需要 html 、 css 、 js .\n",
    "- 可以把这一堆字段串全都写到视图中, 作为 HttpResponse() 的参数, 响应给客户端"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bc5ffbf",
   "metadata": {},
   "source": [
    "**解决问题：**\n",
    "\n",
    "MVT 设计模式：\n",
    "\n",
    "- M全拼为Model，与MVC中的M功能相同，负责和数据库交互，进行数据处理。\n",
    "\n",
    "- V全拼为View，与MVC中的C功能相同，接收请求，进行业务处理，返回应答。\n",
    "\n",
    "- T全拼为Template，与MVC中的V功能相同，负责封装构造要返回的html。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1669263f",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/2.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "47b4db49",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T03:10:41.361080Z",
     "start_time": "2023-10-14T03:10:16.317815Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 11:10:17] \"GET / HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Oct/2023 11:10:23] \"GET /info HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Oct/2023 11:10:26] \"GET /index/123 HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"模版介绍\"\"\"\n",
    "from flask import Flask\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/index/<int:id>')\n",
    "def index(id):\n",
    "    \n",
    "    return '<h1>Hello</h1><p style=\"color:red\">这个是内容！！</p>{name}'\n",
    "\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "892f7902",
   "metadata": {},
   "source": [
    "## 模板的使用\n",
    "在 Flask中，配套的模板是 Jinja2，Jinja2的作者也是Flask的作者，这个模板非常的强大，并且执行效率高。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7bd2a969",
   "metadata": {},
   "source": [
    "**使用步骤：**\n",
    "\n",
    "1. 创建模板\n",
    "    - 在 应用 同级目录下创建模板文件夹 templates . 文件夹名称为固定写法. \n",
    "    - 在 templates 文件夹下, 创建 应用 同名文件夹. 例, Book \n",
    "    - 在 应用 同名文件夹下创建 网页模板 文件. 例 : index.html\n",
    "    \n",
    "2. 设置模板查找路径\n",
    "3. 模板处理数据\n",
    "![](02_Flask-jinjia模版_images/3.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3199d5bf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T03:17:34.169789Z",
     "start_time": "2023-10-14T03:16:29.980808Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 11:16:31] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"模版使用\"\"\"\n",
    "from flask import Flask,render_template\n",
    "\n",
    "\n",
    "# 模板默认查找的目录是templates,\n",
    "# 如果想要修改模板的目录，可以设置template_folder参数\n",
    "app = Flask(__name__, template_folder='template')\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "\n",
    "    return render_template('模版使用.html')\n",
    "\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c00ed9a8",
   "metadata": {},
   "source": [
    "## 模板-传参"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d41c520",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/4.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae52dddf",
   "metadata": {},
   "source": [
    "在使用 render_template 渲染模版的时候，可以传递关键字参数（命名参数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "58e603ef",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T03:35:39.698568Z",
     "start_time": "2023-10-14T03:34:43.553479Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 11:34:46] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Oct/2023 11:34:58] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Oct/2023 11:35:00] \"GET /home HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"模版传参\"\"\"\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('模版传参.html', wu_qi={'jin': '方天画戟', 'yuan': '弓箭'})\n",
    "\n",
    "\n",
    "@app.route('/home')\n",
    "def home():\n",
    "    \"\"\"\n",
    "    小技巧:\n",
    "        如果你的参数项过多，那么可以将所有的参数放到一个字典中，\n",
    "        然后在传这个字典参数的时候，使用两个星号，将字典打散成关键字参数（也叫命名参数）\n",
    "    \"\"\"\n",
    "    context = {\n",
    "        'uname': '吕布',\n",
    "        'age': 18,\n",
    "        'height': 180,\n",
    "        'wu_qi': {'jin': '方天画戟', 'yuan': '弓箭'}\n",
    "    }\n",
    "\n",
    "    return render_template('模版传参.html', **context)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f00d3159",
   "metadata": {},
   "source": [
    "## 模板使用url_for函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e404be3",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/5.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5987d8c4",
   "metadata": {},
   "source": [
    "模版中也可使用 url_for ,和后台视图函数中的 url_for 使用起来基本是一模一样的。\n",
    "\n",
    "提示: 在模板中使用函数，需要在函数 左右两边加上2个 {}, 例如： {{ url_for(func) }}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d595b1cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T14:53:41.053474Z",
     "start_time": "2023-10-14T14:52:53.195696Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 22:52:55] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Oct/2023 22:53:37] \"GET /home2/ HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    # 注意: 无论是 路径参数 还是 查询式参数 都可以直接传递\n",
    "    return render_template('url_for函数的使用.html')\n",
    "\n",
    "@app.route('/home2/')\n",
    "def home():\n",
    "    return 'Home!!'\n",
    "\n",
    "@app.route('/home1/<int:id>')\n",
    "def home1(id):\n",
    "    return 'Home!!'\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b46e0e43",
   "metadata": {},
   "source": [
    "## 过滤器介绍"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24b6d9b3",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/6.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b94b35d6",
   "metadata": {},
   "source": [
    "在模版中，过滤器相当于是一个函数，把当前的变量传入到过滤器中，然后过滤器根据自己的功能，再返回相应的值，之后再将结果渲染到页面中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d882e42d",
   "metadata": {},
   "source": [
    "过滤器是通过管道符号 | 使用的，例如： { name|length }} 将返回name的长度。\n",
    "\n",
    "过滤器相当于是一个函数，把当前的变量传入到过滤器中，然后过滤器根据自己的功能，再返回相应的值，之后再将结果渲染到页面中。\n",
    "\n",
    "Jinja2中内置了许多过滤器 https://jinja.palletsprojects.com/en/3.0.x/templates/#filters"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "688a66e0",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/7.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4edeee7",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/8.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42d2e56d",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/9.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fd1d5053",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T14:57:00.443713Z",
     "start_time": "2023-10-14T14:56:54.054177Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 22:56:55] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"过滤器的初步使用\"\"\"\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('过滤器的使用.html', param=10.5)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "064b7f91",
   "metadata": {},
   "source": [
    "### defalut过滤器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c0af59c8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:02:15.453216Z",
     "start_time": "2023-10-14T15:02:09.907465Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:02:11] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    \n",
    "    return render_template('default过滤器.html', nick_name=None)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3222336f",
   "metadata": {},
   "source": [
    "### 转义字符过滤器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e9a51fcb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:06:41.049969Z",
     "start_time": "2023-10-14T15:05:43.593285Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:05:46] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "jinja2模板 默认全局开启了自动转义功能:\n",
    "\n",
    "    1、safe 过滤器：可以关闭一个字符串的自动转义\n",
    "    \n",
    "    2、escape 过滤器：对某一个字符串进行转义\n",
    "    \n",
    "    3、autoescape 标签，可以对他包含的代码块关闭或开启自动转义 \n",
    "        {% autoescape true/false %} \n",
    "            代码块 \n",
    "        {% endautoescape %}\n",
    "\"\"\"\n",
    "\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    info = '<script>alert(\"Hello!!\")</script>'\n",
    "    return render_template('转义字符过滤器.html',info=info)\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25e3b912",
   "metadata": {},
   "source": [
    "### 其它过滤器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b0786d87",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:08:39.957858Z",
     "start_time": "2023-10-14T15:08:32.172775Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:08:33] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('其它过滤器.html')\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33447727",
   "metadata": {},
   "source": [
    "## 自定义过滤器"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09d48e65",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/10.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2301b82",
   "metadata": {},
   "source": [
    "只有当系统提供的过滤器不符合需求后，才须自定义过滤器\n",
    "\n",
    "过滤器本质上就是一个函数。如果在模版中调用这个过滤器，那么就会将这个变量的值作为第一个参数传给过滤器这个函数，然后函数的返回值会作为这个过滤器的返回值。\n",
    "\n",
    "需要使用到一个装饰器： @app.template_filter('过滤器名称')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e95a5951",
   "metadata": {},
   "source": [
    "### 自定义内容过滤器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "83795d8d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:19:15.898119Z",
     "start_time": "2023-10-14T15:19:09.430485Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:19:10] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.template_filter('cut')\n",
    "def cut(value):\n",
    "    value = value.replace('我是九，你是三，除了你，还是我','你不用好，我喜欢就好')\n",
    "    return value\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    info = '============= 我是九，你是三，除了你，还是我=============='\n",
    "    return render_template('自定义内容过滤器.html',info = info)\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0724fdc2",
   "metadata": {},
   "source": [
    "### 自定义时间过滤器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f3428d1f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:21:22.582626Z",
     "start_time": "2023-10-14T15:21:15.278988Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:21:17] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask, render_template\n",
    "from datetime import datetime\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "# 年 月 日  时 分 秒\n",
    "# 数据库中存放的数据是 2030/01/01 00:00:00\n",
    "# 现在时间是          2030/01/01 01:30:00\n",
    "\n",
    "\n",
    "@app.template_filter('handler_time')\n",
    "def handler_time(time):\n",
    "    '''\n",
    "        time距离现在的时间间隔\n",
    "       1. 如果时间间隔小于1分钟以内，那么就显示“刚刚”\n",
    "       2. 如果是大于1分钟小于1小时，那么就显示“xx分钟前”\n",
    "       3. 如果是大于1小时小于24小时，那么就显示“xx小时前”\n",
    "       4. 如果是大于24小时小于30天以内，那么就显示“xx天前”\n",
    "       5. 否则就是显示具体的时间 2030/10/20 16:15\n",
    "    '''\n",
    "    # 获取当前时间\n",
    "    now = datetime.now()\n",
    "\n",
    "    # 将相差的时间转为秒\n",
    "    temp_stamp = (now-time).total_seconds()\n",
    "\n",
    "    if temp_stamp < 60:\n",
    "        return '1分钟之前'\n",
    "    \n",
    "    elif temp_stamp >= 60 and temp_stamp < 60*60:\n",
    "        return '1小时之前'\n",
    "    \n",
    "    elif temp_stamp >= 60*60 and temp_stamp < 60*60*24:\n",
    "        hours = int(temp_stamp/(60*60))\n",
    "        return f'{hours}小时之前'\n",
    "    \n",
    "    elif temp_stamp >= 60*60*24 and temp_stamp < 60*60*24*30:\n",
    "        day = int(temp_stamp/(60*60*24))\n",
    "        return f'{day}天之前'\n",
    "    \n",
    "    else:\n",
    "        return '很久以前'\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    tmp_time = datetime(2021, 10, 20, 10, 10, 10)\n",
    "    return render_template('自定义时间过滤器.html', tmp_time=tmp_time)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b1c4ee2",
   "metadata": {},
   "source": [
    "## 流程控制-选择结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e9cee2f",
   "metadata": {},
   "source": [
    "所有的控制语句都是放在 {% ... %} 中，并且有一个语句 {% endxxx %} 来进行结束！\n",
    "\n",
    "if：if语句和python中的类似，可以使用 >，<，<=，>=，==，!= 来进行判断，也可以通过 and，or，not，() 来进行逻辑合并操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "00c4bc01",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:25:28.663434Z",
     "start_time": "2023-10-14T15:25:19.396121Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:25:21] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    uname = 'xysz'\n",
    "    return render_template('选择结构.html', uname=uname)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "986d1faf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:28:37.032011Z",
     "start_time": "2023-10-14T15:28:03.779933Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:28:05] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Oct/2023 23:28:09] \"GET /login?user=吕布 HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template,request\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('选择结构练习.html')\n",
    "\n",
    "@app.route('/login') \n",
    "def login():\n",
    "    user = request.args.get('user')\n",
    "    return render_template('选择结构练习.html',user = user)\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db3828a7",
   "metadata": {},
   "source": [
    "## 流程控制-循环结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a34d3f43",
   "metadata": {},
   "source": [
    "for...in... \n",
    "\n",
    "for循环可以遍历任何一个序列包括列表、字典、元组，并且可以进行反向遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "00db5a7d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:34:06.971211Z",
     "start_time": "2023-10-14T15:34:00.502770Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:34:01] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    items = ['Python', 'HTML', 'CSS', 'JavaScript', 'SQL', 'Lua']\n",
    "    person = {'uname': '张三', 'age': 18, 'height': 180, 'nick': '法外狂徒'}\n",
    "    \n",
    "    return render_template('循环结构.html', items=items, person=person)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fce6160f",
   "metadata": {},
   "source": [
    "并且Jinja中的for循环还包含以下变量，可以用来获取当前的遍历状态：\n",
    "\n",
    "![](02_Flask-jinjia模版_images/11.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "601ceef9",
   "metadata": {},
   "source": [
    "**总结：**\n",
    "在 jinja2 中的 for 循环，跟 python 中的 for 循环基本上是一模一样的也是 for...in... 的形式。\n",
    "\n",
    "并且也可以遍历所有的序列以及迭代器唯一不同的是， jinja2 中的 for 循环没有 break 和 continue 语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c31262b1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:35:19.425448Z",
     "start_time": "2023-10-14T15:35:12.999916Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:35:14] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"循环练习-99乘法表\"\"\"\n",
    "\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('循环练习-99乘法表.html')\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cd01696",
   "metadata": {},
   "source": [
    "## 宏的使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3783c61f",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/12.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52b5d57a",
   "metadata": {},
   "source": [
    "模板中的宏 跟python中的函数类似，可以传递参数，但是不能有返回值\n",
    "\n",
    "可以将一些经常用到的代码片段放到宏中，然后把一些不固定的值抽取出来当成一个变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "dc310ac1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:38:50.388301Z",
     "start_time": "2023-10-14T15:38:32.955656Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:38:34] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"定义与使用 宏\"\"\"\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('宏的使用.html')\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04a3b585",
   "metadata": {},
   "source": [
    "**提示：**\n",
    "\n",
    "实际开发中，不会把宏在一个页面内定义 并直接使用\n",
    "\n",
    "一般把宏定义放到一个专门的文件夹中，方便进行统一管理之后，哪一个页面需要使用某个宏，需要导入宏才能使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "93347f9b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:53:36.306893Z",
     "start_time": "2023-10-14T15:53:27.923547Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:53:29] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "\"\"\"宏的导入\"\"\"\n",
    "from flask import Flask, render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    nick = '吕布'\n",
    "    return render_template('宏的引入.html', nick=nick)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b54396e",
   "metadata": {},
   "source": [
    "## 导入模板include"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e0c5031",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/13.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "478b2eab",
   "metadata": {},
   "source": [
    "1. 这个标签相当于是直接将指定的模版中的代码复制粘贴到当前位置。\n",
    "\n",
    "\n",
    "2. include 标签，如果想要使用父模版中的变量，直接用就可以了，不需要使用 with context 。\n",
    "\n",
    "\n",
    "3. include 的路径，也是跟 import 一样，直接从 templates 根目录下去找，不要以相对路径去找。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b49c8046",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T15:56:40.487979Z",
     "start_time": "2023-10-14T15:56:30.941281Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Oct/2023 23:56:32] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('include的使用.html',uname='北理工')\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8990b664",
   "metadata": {},
   "source": [
    "## set与with标签"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a61130d",
   "metadata": {},
   "source": [
    "**set的使用：**\n",
    "\n",
    "在模版中，可以使用 set 语句来定义变量，一旦定义了这个变量，那么在后面的代码中，都可以使用这个变量，就类似于Python的变量定义是一样的\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8660a1f",
   "metadata": {},
   "source": [
    "**with语句：**\n",
    "\n",
    "with 语句定义的变量，只能在 with 语句块中使用，超过了这个代码块，就不能再使用了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9e3450aa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T16:03:54.324662Z",
     "start_time": "2023-10-14T16:03:47.861510Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [15/Oct/2023 00:03:49] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('set与with的使用.html')\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ee83a5c",
   "metadata": {},
   "source": [
    "## 静态文件"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9baaaca",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/14.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e211b3b1",
   "metadata": {},
   "source": [
    "**静态文件：** css文件  js文件  图片文件等文件\n",
    "\n",
    "加载静态文件使用的是 url_for 函数。然后第一个参数需要为 static ，第二个参数需要为一个关键字参数 filename='路径' \n",
    "\n",
    "语法：{{ url_for(\"static\",filename='xxx') }}\n",
    "\n",
    "注意：路径查找，要以当前项目的 static 目录作为根目录，而不是以 templates 作为根目录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e18f168b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T16:12:18.708080Z",
     "start_time": "2023-10-14T16:12:10.506608Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [15/Oct/2023 00:12:11] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "# 设置静态资源的文件夹 -- 默认为 static\n",
    "app = Flask(__name__, static_folder='static2')\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('静态文件引入.html')\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70acab71",
   "metadata": {},
   "source": [
    "## 模板继承"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "965e62fe",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/15.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b08a3c3e",
   "metadata": {},
   "source": [
    "**为什么需要模版继承？**\n",
    "\n",
    "模版继承可以把一些公用的代码单独抽取出来放到一个父模板中\n",
    "\n",
    "以后子模板直接继承就可以使用了，这样可以重复的利用代码，并且以后修改起来也比较方便\n",
    "\n",
    "![](02_Flask-jinjia模版_images/16.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b298934",
   "metadata": {},
   "source": [
    "**模版继承语法**\n",
    "\n",
    "使用 extends 语句，来指明继承的父模板。\n",
    "\n",
    "父模板的路径，也是相对于 templates 文件夹下的绝对路径：{% extends \"base.html\" %}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "712970ea",
   "metadata": {},
   "source": [
    "**block语法**\n",
    "\n",
    "一般在父模版中，定义一些公共的代码。子模板可能要根据具体的需求实现不同的代码。\n",
    "\n",
    "这时候父模版就应该有能力提供一个接口，让子模板来实现。从而实现具体业务需求的功能。\n",
    "\n",
    "![](02_Flask-jinjia模版_images/17.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07a36d26",
   "metadata": {},
   "source": [
    "**调用父模版代码block中的代码**\n",
    "\n",
    "默认情况下，子模板如果实现了父模版定义的block。那么子模板block中的代码就会覆盖掉父模板中的代码。\n",
    "\n",
    "如果想要在子模板中仍然保持父模板中的代码，那么可以使用 {{ super( ) }} 来实现"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "578735f9",
   "metadata": {},
   "source": [
    "![](02_Flask-jinjia模版_images/18.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c657519",
   "metadata": {},
   "source": [
    "**调用另外一个block中的代码**\n",
    "\n",
    "如果想要在另外一个模版中使用其他模版中的代码。那么可以通过 {{ self.其他block名字() }} 就可以了\n",
    "\n",
    "![](02_Flask-jinjia模版_images/19.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a498728",
   "metadata": {},
   "source": [
    "注意：\n",
    "1. 子模板中的代码，第一行，应该是 extends\n",
    "2. 子模板中，如果要实现自己的代码，应该放到block中。如果放到其他地方，那么就不会被渲染"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e1251dee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T16:23:24.649620Z",
     "start_time": "2023-10-14T16:23:11.986157Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [15/Oct/2023 00:23:13] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('模版继承.html')\n",
    "\n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c7b7ea1a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-14T16:30:25.689819Z",
     "start_time": "2023-10-14T16:30:22.621885Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n"
     ]
    }
   ],
   "source": [
    "\"\"\"继承模板实战\"\"\"\n",
    "from flask import Flask,render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('home_base.html')\n",
    "\n",
    "@app.route('/login/')\n",
    "def login():\n",
    "    return render_template('login.html')\n",
    "\n",
    "\n",
    "@app.route('/register/')\n",
    "def register():\n",
    "    return render_template('register.html')\n",
    "    \n",
    "if __name__ =='__main__':\n",
    "    app.run()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8e2b203",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "288px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
